#-------------------------------------------------------------------------------
# Name:        Credits
# Purpose:
#
# Author:      Pablo
#
# Created:     29/04/2013
# Copyright:   (c) Monxcleyr Productions 2013
# Licence:     GPL v3
#-------------------------------------------------------------------------------
#!/usr/bin/env python

import pygame

class Credits():

  """class comment"""

  def __init__(self, surface, common, starfield):
    self.surface = surface
    self.common = common
    self.bg = pygame.image.load('resources/graphics/credits/bg.bmp')
    self.bg.set_colorkey((255,0,255))
    self.bgpos = ((self.common.initsize[0]/2) - (self.bg.get_width() / 2), (self.common.initsize[1]/2) - (self.bg.get_height() / 2))
    self.credits = pygame.image.load('resources/graphics/credits/credits.bmp')
    self.count = 0
    self.creditpos = (0, self.bg.get_height())
    self.fade = pygame.Surface(self.common.initsize)
    self.fade.fill((0,0,0))
    self.fade.set_alpha(0)
    self.alpha = 0
    self.starfield = starfield
    self.time = 0
    self.firstdraw = True
    self.ypos = self.creditpos[1]
    # 1000

  def run(self, time):

    if self.firstdraw == True:
      self.time = 200 - time
      self.firstdraw = False

    pygame.mixer.music.stop()

    self.count += 1

    self.surface.fill((0,0,0))

    key = pygame.key.get_pressed()

    self.starfield.draw(self.surface)

    self.ypos -= (self.time * .005)

    self.creditpos = (self.creditpos[0], self.ypos)

    self.bg.blit(self.credits, self.creditpos)
    self.surface.blit(self.bg, self.bgpos)

    if self.ypos < -440:

      self.alpha += 2.55
      self.fade.set_alpha(self.alpha)
      self.surface.blit(self.fade, (0,0))
      if self.alpha >= 255:
        return True
